package com.bm.controller;
import com.bm.Result.Result;
import com.bm.Vo.Notice.DetailNoticeVo;
import com.bm.Vo.Notice.UpdateNoticeVo;
import com.bm.page.PageBean;
import com.bm.query.Common.InfoQuery;
import com.bm.query.Notice.NoticeListQuery;
import com.bm.query.Notice.NoticeNewUserNotificationQuery;
import com.bm.service.EjyyNoticeToUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;


@RestController
@Api(tags = "用户通知")
public class NoticeToUserController {

    @Autowired
    private EjyyNoticeToUserService ejyyNoticeToUserService;

    /**
     * 分页查询用户通知
     * @return 返回成功信息和查询到的数据
     */
    @PostMapping("/notice/list")
    @ApiOperation(value = "分页查询用户通知")
    public Result NoticeList(@RequestBody NoticeListQuery noticeListQuery){
        //LambdaQueryWrapper<EjyyNoticeToUser> wrapper = ejyyNoticeToUserService.PaginationQuery(pageNum, pageSize, communityId, published);
        //分页查询
        //ejyyNoticeToUserService.page(page,wrapper);
        PageBean pageBean = ejyyNoticeToUserService.Pagination(noticeListQuery);
        return Result.OK(pageBean);
    }

    /**
     * 新增用户通知
     * @param noticeNewUserNotificationQuery 新增用户方法
     * @return 返回失败或成功信息
     */
    @PostMapping("/notice/create")
    @ApiOperation(value = "新增用户通知")
    public Result NoticeCreate(@RequestBody NoticeNewUserNotificationQuery noticeNewUserNotificationQuery){
        //新增用户通知
        ejyyNoticeToUserService.VerifyData(noticeNewUserNotificationQuery);
        return Result.OK("新增通知成功");
    }

    /**
     * 查询用户通知详细信息
     * @return
     */
    @PostMapping("/notice/detail")
    @ApiOperation(value = "查询用户通知详细信息")
    public Result NoticeDetail(@RequestBody InfoQuery infoQuery){
        DetailNoticeVo NoticeData = ejyyNoticeToUserService.PagingCondition(infoQuery);
        return Result.OK(NoticeData);
    }

    /**
     * 修改用户通知
     * @param updateNoticeVo 用户修改数据
     * @return
     */
    @PostMapping("/notice/update")
    @ApiOperation(value = "修改用户通知")
    public Result NoticeUpdate(@RequestBody UpdateNoticeVo updateNoticeVo){
        Boolean updated = ejyyNoticeToUserService.updateNotice(updateNoticeVo);
        if (updated){
            return Result.OK("修改通知成功");
        }
        return Result.FAIL("修改通知失败");
    }

    /**
     * 用户已发部通知
     * @param infoQuery
     * @return
     */
    @PostMapping("/notice/published")
    @ApiOperation(value = "用户已发部通知")
    public Result NoticePublished(@RequestBody InfoQuery infoQuery){
        Boolean flag = ejyyNoticeToUserService.Published(infoQuery);

        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String format = dateFormat.format(date);
        return flag ? Result.OK(Long.parseLong(format)) : Result.FAIL("发布通知失败");
    }

    @GetMapping("/notice/tpl")
    @ApiOperation(value = "第三方通知 (未完成 以后再写)")
    public Result tpl(){
        return null;
    }

}
